package JDBC;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class JDBCDemo1 {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        /*
        * 使用JDBC链接书库并操作的基本流成
        * */
        //1
        Class.forName("com.mysql.cj.jdbc.Driver");
        //2
 Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/tedu?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true",
                "root","root");
        System.out.println("成功链接数据库");
//成功链接数据库
        Statement statement = connection.createStatement();

   String sql= "     CREATE TABLE userinfo(\n" +
           "         id INT PRIMARY KEY AUTO_INCREMENT,\n" +
           "         username VARCHAR(30),\n" +
           "         password VARCHAR(30),\n" +
           "         nickname VARCHAR(30),\n" +
           "         age INT (3)\n" +
           "         )";
   statement.execute(sql);
        System.out.println("执行完毕");


        connection.close();
    }
}
